<%@page pageEncoding = "utf-8" contentType = "text/html;charset=utf-8"%>

<%@taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix = "fmt" uri = "http://java.sun.com/jsp/jstl/fmt"%>
<%@taglib prefix = "fn" uri = "http://java.sun.com/jsp/jstl/functions"%>

<h2><fmt:message key = "form.listOrganizations"/></h2>

<div class = "messages"><jsp:include page = "/messages.jsp"/></div>

<p>
  <a href = "adminui?_action=organizationForm">
    <fmt:message key = "Command.add"/>
  </a>
</p>

<p>
<a href="adminui?_action=organizationsList&type=all">
  <fmt:message key="Command.all"/>
</a>

<a href="adminui?_action=organizationsList&type=active">
  <fmt:message key="Command.active"/>
</a>

<a href="adminui?_action=organizationsList&type=inactive">
  <fmt:message key="Command.inactive"/>
</a>
</p>

<table width="100%" cellpadding="10" cellspacing="10">
      <thead>
         <tr  style="border-bottom: 1px #f1f1f1 solid;">            
         	<th><a class="head" href="adminui?_action=organizationsList&orderBy=N&order=${order}&type=${type}">#</a></th>
            <th><a class="head" href="adminui?_action=organizationsList&orderBy=name&order=${order}&type=${type}"><fmt:message key = "organization.shorttitle"/></a></th>
            <th><fmt:message key = "organization.tel1"/></th>            
            <th><a class="head" href="adminui?_action=organizationsList&orderBy=email&order=${order}&type=${type}"><fmt:message key = "organization.email1"/></a></th>
            <th><fmt:message key = "organization.www"/></th>
            <th><fmt:message key = "organization.operations"/></th>
         </tr>
      </thead>

      <tbody>
         <c:forEach var = "organization" items = "${organizationsList}">
            <tr style="border-bottom: 1px #f1f1f1 solid;">
               <td>${organization.id}</td>
               <td><c:out value="${organization.shortTitle}"/></td>
               <td><c:out value="${organization.tel1}"/></td>               
               <td><a href="mailto:${organization.email1}">${organization.email1}</td>
               <td><a href="<c:out value='${organization.www}'/>"><c:out value='${organization.www}'/></a></td>               
               <td>
                 <a href = "adminui?_action=departmentsList&organization_id=${organization.id}">
                   <fmt:message key = "organization.operations.department"/>
                 </a> <br>  

                 <a href = "adminui?_action=organizationForm&organization_id=${organization.id}">
                   <fmt:message key = "client.operations.edit"/>
                 </a> <br>

                 <c:choose>
                   <c:when test="${organization.status == 'active'}">                     
                     <a href = "adminui?_action=setOrganizationStatus&status=delete&orderBy=${orderBy}&order=${order}&type=${type}&organization_id=${organization.id}" 
                       onclick="return confirm('Вы действительно хотите удалить организацию?')"
                     >
                       <fmt:message key = "client.operations.remove"/>
                     </a>                      
                   </c:when>
                 <c:otherwise>
                   <a href = "adminui?_action=setOrganizationStatus&status=restore&orderBy=${orderBy}&order=${order}&type=${type}&organization_id=${organization.id}">
                     <fmt:message key = "client.operations.restore"/>
                   </a>
                 </c:otherwise>     
                 </c:choose>  
               </td>
            </tr>
         </c:forEach>

        <c:if test="${fn:length(organizationsList) == 0}">
          <tr><td colspan = "6" align="center"><fmt:message key="emptyList"/></td></tr>
        </c:if>

      </tbody>
</table>

<p>
  <a href = "adminui?_action=organizationForm">
    <fmt:message key = "Command.add"/>
  </a>
</p>